<script setup>
import { onMounted, getCurrentInstance } from 'vue'
import { usernameStore, cartCountStore } from '@/store/index.js'

const { proxy } = getCurrentInstance()
const { saveUserName } = usernameStore()
const { saveCartCount } = cartCountStore()
onMounted(() => {
  if (proxy.$cookies.get('userId')) {
    getUser()
    getCartCount()
  }
})
const getUser = () => {
  proxy.axios.get('/user').then((res = {}) => {
    saveUserName(res.username)
  })
}
const getCartCount = () => {
  proxy.axios.get('/carts/products/sum').then((res = 0) => {
    saveCartCount(res)
  })
}
</script>

<template>
  <router-view></router-view>
</template>

<style lang="scss">
@import url('@/assets/base.scss');
@import url('@/assets/reset.scss');
@import url('@/assets/button.scss');
</style>